// pages/myCourse/myCourse.js
import {courseAllorder, courseAllorderByStatus} from "../../services/courseReq";

const {
    courseAll
} = require("../../services/courseReq");
Page({
    /**
     * 页面的初始数据
     */
    data: {
        isShow: true,
        courseList: [],
        active: 0,
        pageNum: 1,
        pageSize: 10,
        isFinish: false,
        totalCount: 10,
        allCourseList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onReachBottom() {
        // let pageNum = this.data.pageNum;
        // this.setData({
        //     pageNum: pageNum + 1,
        // })
        // if (this.data.active === 0) return null;
        //
        // this.handleGetCourse(1);

    },
    onShow: function (options) {
        // let userid = wx.getStorageSync("volunteerInfo").volunteerId;
        const params = {
            status: 1
        }
        let courseList = this.data.courseList;
        wx.showLoading({
            title: "Loading..."
        })
        courseAllorderByStatus(params, (res) => {
            courseList = res.data.data;
            this.setData({
                courseList
            })
            wx.hideLoading()
        })

    },
    handleGoMyCourse() {
    },
    handleShow() {
        let isShow = this.data.isShow;
        isShow = !isShow;
        if (isShow) {
            //    展示进行中的课程

        } else {
            //    展示全部的课程

        }
        return this.setData({
            isShow
        })
    },
    handleGetDetail(event) {
        console.log(event)
        const id = event.currentTarget.dataset.courseid;
        wx.navigateTo({
            url: "../courseArrange/courseArrange?id=" + id
        })
    },
    handleGetCourse(e) {
        // e.detail.index
        let courseList = this.data.courseList;
        let allCourseList = this.data.allCourseList;
        let pageSize = this.data.pageSize;
        let pageNum = this.data.pageNum;
        let isFinish = this.data.isFinish;
        let index = e?.detail.index ?? e;

        switch (index) {
            case 0:
                let params = {
                    status: 1
                }
                courseAllorderByStatus(params, res => {
                    courseList = res.data.data;
                    this.setData({
                        courseList,
                    })
                })

                break;
            case 1:
                // if (this.data.totalCount <= this.data.allCourseList.length) return null;
                courseAllorder({pageNum, pageSize:999}, res => {
                    // console.log(`res-->`, res)
                    this.setData({
                        allCourseList: res.data.data.records,
                        // totalCount: res.data.data.totalCount,
                    })
                })

                break;

        }


    },


});
